import 'package:cached_network_image/cached_network_image.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_yyt/models/dynamic_entity.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/util/utils.dart';
import 'package:ls_work/widgets/gallery_photo_browser.dart';
import 'package:ls_work/widgets/load_image.dart';
import 'package:ls_work/res/resources.dart';

import '../../login/page/user_manager.dart';

class DynamicCell extends StatelessWidget {
  final DynamicInfo? info;
  DynamicCell({Key? key, this.info});
  @override
  Widget build(BuildContext context) {
    String name = info?.elderName ?? '';
    String branchName = info?.branchName ?? '';
    String nurseLevelName = info?.nurseLevelName != null ? '护理${info?.nurseLevelName}级' : '';
    String buildingNo = info?.buildingNo ?? '';
    String floorNo = info?.floorNo ?? '';
    String roomNo = info?.roomNo ??'';
    String content  = info?.content ?? '';
    List<int> titleList = [];
    if (info?.attachList != null && (info?.attachList??[]).length > 0) {
      for (var f in info!.attachList!) {
        print(f.id);
        titleList.add(f.id);
      }
      print('-----');
    }

    return Container(
      width: double.infinity,
      padding: EdgeInsets.fromLTRB(20, 8, 12, 8),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              // CircleAvatar(
              //   backgroundColor: Colours.bg_gray,
              //   radius: 20,
              //   backgroundImage: AssetImage('assets/default/d_mrtx'),
              // ),
              LoadAssetImage('default/d_mrtx'),
              SizedBox(
                width: 13,
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '$name',
                    style: TextStyles.textBoldDark14,
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Text(
                    '$nurseLevelName  $branchName  $buildingNo#$floorNo-$roomNo',
                    style: TextStyles.textGray12,
                  ),
                ],
              ),
            ],
          ),
          SizedBox(
            height: 15,
          ),
          Text(
            '$content',
            style: TextStyles.textDark16,
          ),
          SizedBox(
            height: 10,
          ),
          titleList.length <= 0 ? Container() :
          GridView.builder(
            physics: NeverScrollableScrollPhysics(),
            shrinkWrap: true,
            itemCount: titleList.length,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3,
              mainAxisSpacing: 10,
              crossAxisSpacing: 10,
            ),
            itemBuilder: (BuildContext context, int index) {
              return InkWell(
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => GalleryPhotoViewWrapper(
                        galleryItems: titleList,
                        backgroundDecoration: const BoxDecoration(
                          color: Colors.black,
                        ),
                        initialIndex: index,
                      ),
                    ),
                  );
                },
                child: ClipRRect(
                    borderRadius: BorderRadius.circular(6),
                    child: CachedNetworkImage(
                      width: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
                      height: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
                      fit: BoxFit.cover,
                      imageUrl: '${HttpApi.imageDownLoadUrl}${titleList[index]}',
                        httpHeaders: {"Cookie":UserManager.cookieStr},
                      placeholder: (context, url) => new ProgressView(),
                      errorWidget: (context, url, error) =>
                          new Icon(Icons.error, color: Colors.black,),
                    )),
              );
            },
          )
        ],
      ),
      // child: Column(
      //   mainAxisAlignment: MainAxisAlignment.start,
      //   crossAxisAlignment: CrossAxisAlignment.start,
      //   children: <Widget>[
      //     Row(
      //       mainAxisAlignment: MainAxisAlignment.start,
      //       crossAxisAlignment: CrossAxisAlignment.start,
      //       children: <Widget>[
      //         // CircleAvatar(
      //         //   backgroundColor: Colours.bg_gray,
      //         //   radius: 20,
      //         //   backgroundImage: AssetImage('assets/default/d_mrtx'),
      //         // ),
      //         LoadAssetImage('default/d_mrtx'),
      //         SizedBox(
      //           width: 13,
      //         ),
      //         Column(
      //           mainAxisAlignment: MainAxisAlignment.start,
      //           crossAxisAlignment: CrossAxisAlignment.start,
      //           children: <Widget>[
      //             Text(
      //               '$name',
      //               style: TextStyles.textBoldDark14,
      //             ),
      //             SizedBox(
      //               height: 5,
      //             ),
      //             Text(
      //               '$nurseLevelName  $branchName  $buildingNo#$floorNo-$roomNo',
      //               style: TextStyles.textGray12,
      //             ),
      //           ],
      //         ),
      //       ],
      //     ),
      //     SizedBox(
      //       height: 15,
      //     ),
      //     Text(
      //       '$content',
      //       style: TextStyles.textDark16,
      //     ),
      //     SizedBox(
      //       height: 10,
      //     ),
      //     Row(
      //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
      //       crossAxisAlignment: CrossAxisAlignment.start,
      //       children: titleList.map((f) {
      //         return GestureDetector(
      //           onTap: () {
      //             // AppNavigator.push(
      //             //     context,
      //             //     PhotoBrowser(
      //             //       imgUrlList: titleList,
      //             //       currentPageValue: 0,
      //             //     ));
      //           },
      //           child: ClipRRect(
      //             borderRadius: BorderRadius.circular(6),
      //             child: CachedNetworkImage(
      //               width: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
      //               height: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
      //               fit: BoxFit.fill,
      //               imageUrl: f,//HttpApi.baseUrl + '/commonAttachDown/download?id=' + '${f.id}'
      //               placeholder: (context, url) => new ProgressView(),
      //               errorWidget: (context, url, error) => new Icon(Icons.error),
      //             ),
      //             // LoadImage(
      //             //   f,
      //             //   width: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
      //             //   height: (ScreenUtil.getScreenW(context) - 32 - 20) / 3,
      //             //   holderImg: 'none',
      //             // ),
      //           ),
      //         );
      //       }).toList(),
      //     ),
      //   ],
      // ),
    );
  }
}
